﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TTBusiness.DB_Linq;
using TTBusiness.ClassProject;
using TTBusiness.ClassDB;
namespace TTMarketing.UserControl.SanPham
{
    public partial class ucProductDetail : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void RadListView1_ItemCommand(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("Mua"))
                {
                    List<TTBusiness.ClassProject.clsBSOrder> order = new List<TTBusiness.ClassProject.clsBSOrder>();
                    if (Session["order"] != null)
                    {
                        order = (List<TTBusiness.ClassProject.clsBSOrder>)Session["order"];
                    }
                    TTBusiness.ClassProject.clsBSOrder obj = new TTBusiness.ClassProject.clsBSOrder();
                    obj.ProductId = Convert.ToInt32(e.CommandArgument);
                    bool check = true;
                    for (int i = 0; i < order.Count; i++)
                    {
                        if (order[i].ProductId.Equals(obj.ProductId))
                        {
                            order[i].Count = order[i].Count + 1;
                            check = false;
                            break;
                        }
                    }
                    if (check)
                    {
                        obj.Count = 1;
                        order.Add(obj);
                    }
                    Session["order"] = order;
                    Response.Redirect("~/gio-hang.aspx");
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        public static string getNameCateByFactoryId(string factoryid)
        {
            try
            {
                clsBSCateFactory obj = new clsBSCateFactory();
                return obj.getById(Convert.ToInt32(factoryid)).tblCateProduct.Name;
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        public static string getNameTypeByFactoryId(string factoryid)
        {
            try
            {
                clsBSCateFactory obj = new clsBSCateFactory();
                return obj.getById(Convert.ToInt32(factoryid)).tblCateProduct.tblTypeProduct.Name;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}